package com.music.music.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.music.common.log.annotation.Log;
import com.music.common.log.enums.BusinessType;
import com.music.common.security.annotation.RequiresPermissions;
import com.music.music.domain.Singer;
import com.music.music.service.SingerService;
import com.music.common.core.web.controller.BaseController;
import com.music.common.core.web.domain.AjaxResult;
import com.music.common.core.utils.poi.ExcelUtil;
import com.music.common.core.web.page.TableDataInfo;

/**
 * 歌手列表Controller
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/singer")
public class SingerController extends BaseController
{
    @Resource
    private SingerService singerService;

    /**
     * 查询歌手列表列表
     */
    @RequiresPermissions("music:singer:list")
    @GetMapping("/list")
    public TableDataInfo list(Singer singer)
    {
        startPage();
        List<Singer> list = singerService.selectSingerList(singer);
        return getDataTable(list);
    }

    /**
     * 导出歌手列表列表
     */
    @RequiresPermissions("music:singer:export")
    @Log(title = "歌手列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Singer singer)
    {
        List<Singer> list = singerService.selectSingerList(singer);
        ExcelUtil<Singer> util = new ExcelUtil<Singer>(Singer.class);
        util.exportExcel(response, list, "歌手列表数据");
    }

    /**
     * 获取歌手列表详细信息
     */
    @RequiresPermissions("music:singer:query")
    @GetMapping(value = "/{singerId}")
    public AjaxResult getInfo(@PathVariable("singerId") Long singerId)
    {
        return success(singerService.selectSingerBySingerId(singerId));
    }

    /**
     * 新增歌手列表
     */
    @RequiresPermissions("music:singer:add")
    @Log(title = "歌手列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Singer singer)
    {
        return toAjax(singerService.insertSinger(singer));
    }

    /**
     * 修改歌手列表
     */
    @RequiresPermissions("music:singer:edit")
    @Log(title = "歌手列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Singer singer)
    {
        return toAjax(singerService.updateSinger(singer));
    }

    /**
     * 删除歌手列表
     */
    @RequiresPermissions("music:singer:remove")
    @Log(title = "歌手列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{singerIds}")
    public AjaxResult remove(@PathVariable Long[] singerIds)
    {
        return toAjax(singerService.deleteSingerBySingerIds(singerIds));
    }


}
